@extends('admin.layout')

@section('content')
<div class="content-wrapper" style="min-height: 916px;">
        <div id="breadcrumbs" class="breadcrumbs">
            <ol class="breadcrumb">
            <li><a href="javascript:void();"><i class="fa fa-home"></i>&nbsp;&nbsp;后台首页</a></li>
                    
                    <li><a href="javascript:void();">会员管理</a></li>    
                    <li><a href="javascript:void();">用户列表</a></li>          
            </ol>
        </div>

        <section class="content">
        <div class="container-fluid">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 用户列表</h3>
                </div>
                <div class="panel-body">
                    <div class="box-header">
                      <nav class="navbar navbar-default">      
                          <div class="collapse navbar-collapse">
                            <form method="get" action="{{ asset('admin/user/member') }}" class="navbar-form form-inline">
                              <div class="form-group">
                                   <input type="text" value="{{ $request['keyword']  or '' }}" name="keyword" class="form-control" placeholder="请输入邮箱地址">
                              </div>
                              <button class="btn btn-default" type="submit">查找</button>
                              <div class="form-group pull-right">
                                  <a class="btn btn-primary pull-right" href="{{ asset('/admin/user/add') }}"><i class="fa fa-plus"></i>添加会员</a>
                              </div>                
                            </form>        
                          </div>
                      </nav>  
                   </div> 
                    <div id="ajax_return">                   
                     <form id="form-order" target="_blank" enctype="multipart/form-data" method="post">
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                  
                                    <td class="text-right">
                                        <a href="javascript:sort('user_id');">ID</a>
                                    </td>
                                    <td class="text-left">
                                        <a href="javascript:sort('username');">用户头像</a>
                                    </td>
                                    <td class="text-left">
                                        <a href="javascript:sort('username');">会员昵称</a>
                                    </td>
                                    <td class="text-left">
                                        <a href="javascript:sort('level');">用户名</a>
                                    </td>
                                    <td class="text-left">
                                        <a href="javascript:sort('total_amount');">邮件地址</a>
                                    </td>
                                    <td class="text-left">
                                        <a href="javascript:sort('email');">手机号码</a>
                                    </td>
                                    
                                    <td class="text-left">
                                        <a href="javascript:sort('mobile');">用户积分</a>
                                    </td>
                                    <td class="text-left">
                                        <a href="javascript:sort('mobile');">用户状态</a>
                                    </td>
                                    <td class="text-left">
                                        <a href="javascript:sort('pay_points');">注册日期</a>
                                    </td>
                                    <td class="text-left">
                                        <a href="javascript:sort('pay_points');">更新时间</a>
                                    </td>
                                    <td class="text-left">
                                        <a href="javascript:sort('reg_time');">上次登录时间</a>
                                    </td>
                                    <td class="text-right">操作</td>
                                </tr>
                                </thead>
                                <tbody>
                                 @foreach($data as $user)
                                   
                                    <tr align="center" role="row">
                                       <td class="ids" value="{{ $user -> id}}">
                                        {{ $user -> id }}
                                       </td>
                                       <td><img width="40" height="40" src="{{ $user -> photo }}"></td>
                                       <td>{{ $user -> nickname}}</td>
                                       <td>{{ $user -> name}}</td>
                                       <td>{{ $user -> email}}</td>
                                       <td>{{ $user -> phone}}</td>
                                       <td>1</td>
                                       
                                      <td class="std btn">
                                       @if($user -> status == 1)
                                          <span class=" btn btn-success">启用</span> 
                                       @else
                                          <span class=" btn btn-danger">禁用</span> 
                                       @endif
                                       </td>
                                      
                                       
                                       <td>{{ $user -> created_at}}</td>
                                       <td>

                                        @if(!empty($user -> updated_at))

                                          {{ $user -> updated_at}}
                                        @else
                                            无更新
                                        @endif

                                       </td>
                                       <td>
                                        @if(!empty($user -> last_time))
                                           {{ $user -> last_time}}
                                        @else
                                            未登录
                                        @endif

                                       </td>
                                       <td>

                                        <a data-original-title="查看详情" class="btn btn-info" title="" data-toggle="tooltip" href="/index.php/Admin/user/detail/id/1148"><i class="fa fa-eye"></i></a>
                                        <a data-original-title="删除" class="btn btn-danger" title="" data-toggle="tooltip" id="button-delete6" href="/index.php/Admin/user/delete/id/1148"><i class="fa fa-trash-o"></i></a>  
                                      </td>
                                     </tr> 
                                  
                                  @endforeach      
                                                  
                                    </tbody>
                            </table>
                        </div>
                    <div class="row">
                        <div class="col-sm-12 text-right">
                          {!! $data -> appends($request) -> render() !!}
                        </div>
                    </div>
<script>
    $(".pagination  a").click(function(){
        var page = $(this).data('p');
        ajax_get_table('search-form2',page);
    });
</script></div>
                </div>
            </div>
        </div>        <!-- /.row -->
    </section>
    </div>
    <script type="text/javascript">
        
        window.onload = function()
        {

            //自动清楚提示框
            setTimeout("$('#showHidden').hide( )",3000); 
            // alert($);
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });

                //添加事件
                
                //鼠标移入事件
                $('.std, .name').on('mouseover', function(){

                    $(this).css({cursor:'pointer', color:'blue'});
                })
                //鼠标移出事件
                $('.std, .name').on('mouseout', function(){

                    $(this).css({cursor:'default', color:'black'});
                })
                


                $('.std').on('click', function(){
                    var std = $(this);
                    var id = $(this).parent().find('.ids').html();
                    // var id = $(this ).parent().children().first().html();
                    
                    // alert(id);
                    $.post('/admin/user/ajaxUpdate',{id:id},function(data){
                        if(data =='0')
                        {
                            std.html('禁用');
                        }else if(data == '2')
                        {
                            std.html('启用');
                        }
                    },'json');

                });

                function dblClick()
                {
                    var td = $(this);
                    //获取原ID
                    var id = td.prev().html();
                    //获取原value值
                    var name= td.html();

                    var inp = $('<input type="text" />');
                    inp.val(name);

                    //将表单放到TD中
                    td.html(inp);
                    //自动对焦
                    inp.select();
                    //失去焦点
                    inp.blur(function()
                    {
                        //获取新值
                        var newName = inp.val();

                        if(name == newName)
                        {
                            // alert('你脑子有病');
                            td.html(name);
                            //添加事件
                            td.dblclick(dblClick);
                            return ;
                        }

                        //ajax
                        $.post('/admin/user/ajaxUsername',{id:id,name:newName},
                            function(data)
                            {
                                if(data == '1')
                                {
                                    alert('用户名已存在');
                                    td.html(name);
                                }else if(data == '0')
                                {
                                    td.html(newName);
                                }else
                                {
                                    alert('用户修改失败');
                                    td.html(name);
                                }
                            },'json');  
                        //添加事件
                        td.dblclick(dblClick);
                    });

                    //清除事件
                    td.unbind('dblclick');
                }

                //双击修改用户名
                $('td[class=name]').on('dblclick',dblClick);
        }

    </script>

@endsection